﻿using System;
using AMM.Business;
using AMM.Model;
using AMM.Model.Produce;

namespace AMM.UserControls {
    public partial class ProducePlanSearchControl : BaseSearchControl {

        public override BaseSearchModel GetSearchModel() {
            int produceUnitValue = Convert.ToInt32(this.cmbProduceUnit.SelectedValue);

            ProducePlanSearchModel searchResult = new ProducePlanSearchModel();
            searchResult.PlanDateStart = this.GetDateTimePickerValue(this.dtpPlanStart);
            searchResult.PlanDateEnd = this.GetDateTimePickerValue(this.dtpPlanEnd);
            searchResult.ProduceProductCode = this.tbProduceConductCode.Text;
            searchResult.ProductCode = this.tbProductCode.Text;
            searchResult.ProduceUnitId = produceUnitValue;

            if (produceUnitValue == 0) { searchResult.ProduceUnitId = null; }

            return searchResult;
        }

        public override void ResetSearchModel() {
            this.dtpPlanStart.Checked = false;
            this.dtpPlanEnd.Checked = false;
            this.tbProductCode.Clear();
            this.tbProduceConductCode.Clear();
            this.cmbProduceUnit.SelectedValue = 0;
        }

        public ProducePlanSearchControl() {
            this.InitializeComponent();
        }

        private void ProducePlanSearchControl_Load(object sender, EventArgs e) {
            this.BindBasics(this.cmbProduceUnit, BasicsType.ProduceUnit);
        }
    }
}
